#pragma once
#include <string>
#include <iostream>
using namespace std;

string opers = "+-*/%^~"; // 将操作符存在一起好生成随机操作符

enum // 枚举常量，标识结果码
{
    correct = 0,
    div_0,
    mol_0,
    none
};
class task
{
public:
    task() // 重载一个默认构造，好让消费者接受数据
    {
    }
    task(int x, int y, char ope)
        : _x(x), _y(y), _operat(ope), _result(0)
    {
    }
    void operator()() // 仿函数
    {
        run();
    }
    void run()
    {
        switch (_operat)
        {
        case '+':
            _result = _x + _y;
            break;
        case '-':
            _result = _x - _y;
            break;
        case '*':
            _result = _x * _y;
            break;
        case '/':
        {
            if (_y == 0)
                _code = div_0;
            _result = _x / _y;
        }
        break;
        case '%':
        {
            if (_y == 0)
                _code = mol_0;
            _result = _x % _y;
        }
        break;
        default:
            _code = none;
        }
    }
    void proc_print()
    {
        cout << "生产者：" << _x << ' ' << _operat << ' ' << _y << " = " << endl;
        ;
    }
    void consu_print()
    {
        cout << "消费者：" << _x << ' ' << _operat << ' ' << _y << " = " << _result << '[' << _code << ']' << endl;
        ;
    }

private:
    int _x;
    int _y;
    int _result;
    char _operat;
    int _code;
};
